package com.myx.design.single.realization;

/**
 * 描述:单例模式-枚举
 * 使用枚举实现单例模式 优点:实现简单、枚举本身就是单例，由jvm从根本上提供保障!避免通过反射和反序列化的漏洞 缺点没有延迟加载
 * @author: myx
 * @date: 2018/11/28
 * Copyright © 2018-hotpot. All rights reserved.
 */
public class UserSingleEumn {
    private enum UserEnum{
        INSTANCE;
        private UserSingleEumn userSingleEumn;
        //每个枚举只执行一次
        private UserEnum(){
            userSingleEumn=new UserSingleEumn();
        }
        public UserSingleEumn getInstance() {
            return userSingleEumn;
        }
    }
    private UserSingleEumn(){
    }
    public static UserSingleEumn getInstance() {
        return UserEnum.INSTANCE.getInstance();
    }

    public static void main(String[] args) {
        System.out.println(UserSingleEumn.getInstance()==UserSingleEumn.getInstance());
    }

}
